{extend name="admininfo/admininfo" /}
{block name='main'}
<h2>专辑列表</h2>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加专辑
                </h4>
            </div>
 
        </div><!-- /.modal-content -->           
        <form class="form-horizontal" action="add" method='post' enctype="multipart/form-data">

                <div class="modal-body">
                    
                    <table class="table table-bordered">
                        <tr>
                            <td>专辑名</td>
                            <td><input type="text" name='name'></td>
                        </tr>
                        <tr>
                            <td>演唱歌手</td>
                            <td><input type="text" id='singer' name='singer'></td>
                        </tr>
                        <tr>
                            <td>类型</td>
                            <td>
                                <select name="style" id="">
                                    {foreach $res as $k => $v}
                                    <optgroup label="{$k}">

                                    {foreach $v as $a => $b}
                                    <option value="{$b}">{$b}</option>

                                    {/foreach}
                                    {/foreach} 
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>图片</td>
                            <td><input type="file" name='image'></td>
                        </tr>
                        <tr>
                            <td>描述</td>
                            <td>
                                <textarea name="dsc" id="" cols="30" rows="10" ></textarea>
                            </td>
                        </tr>
                    </table>  
                             
        
                
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button class="btn btn-primary adds" type='submit'>
                        保存
                    </button>
                </div>
            </form>
    </div><!-- /.modal -->
</div>




   <button class="btn btn-default btn-success add" date_id="" data-toggle="modal" data-target="#myModal" >
    添加专辑
   </button>

<table class="table table-hover table-bordered" style="text-align: center;">
  
    <tr>
        <th style="text-align: center;">
            id
        </th>
        <th style="text-align: center;">
            IMG
        </th>
        <th style="text-align: center;">
            name
        </th>
        <th style="text-align: center;">
            歌手
        </th>
       <th style="text-align: center;">
           地区
       </th>

        <th style="text-align: center;">
            操作
        </th>
    </tr>


    {foreach $list as $v}
    <tr id='{$v.id}'>
        <td>
            {$v.id}
        </td>
        <td>
           <img src="__UPLOAD__/{$v.imgs}" alt="" width="50px">

        </td>
        <td>
            {$v.name}

        </td>
        <td>
            {$v.singer}
        </td>
        <td>
            {$v.style}
        </td>
  
        <td>
            <div class="row clearfix">
                 <!--<div class="col-md-12 column" >-->


                    <a href="{:url('admin/Specials/edit',['id'=>$v.id])}"  class="btn btn-default btn-success add"  data_id="{$v.id}" >
                        编辑
                    <a/>
                    <a  class="btn btn-default btn-danger" id='del' data_id="{$v.id}" >删除</a>

                 <!--</div>-->
            </div>
        </td>
    </tr>
    {/foreach}
</table>




<script>

$(function(){


    //添加专辑是获取歌手
    $("#singer").blur(function(){
        var singer = $('#singer').val();
        $.ajax({
            type:'post',
            url:  'singer',
            data:{ 'singer': singer },
            dataType:'json',
            success:function(data){
                // console.log($(this).parents('tr').remove());
                if (data===null) {
                 // $("#singer").css("border","1px solid red");
                 var HTM = "<b style='color:red'>数据库无此歌手请添加</b>"
                 $('#singer').after(HTM)
                }
                
            }

        })

    });

    $("#singer").focus(function(){ 
        $('#singer').next().remove()
    }); 


    //删除专辑
   $(document).on('click', '#del', function(e) {
        var result = confirm('你确定删除此专辑');
        var data_id = $(this).attr('data_id');
        console.log(data_id);
        if (result) {
           $.ajax({
                type:'post',
                url: 'del',
                data:{ 'id': data_id },
                dataType: 'json',
                success:function(data){
                    console.log(data);
                    if (data>0) {
                     $('#'+data_id).remove();
                     alert('删除成功');

                    }else {
                     alert('删除失败'); 
                    }
                }
            })
        }
    })



})

</script>
<div>
    {$list->render()}
</div>
{/block}